package com.hui.web.servlet.studentServlet;

import com.hui.bean.RoomBean;
import com.hui.service.IRoomService;
import com.hui.service.IStudentService;
import com.hui.service.impl.RoomServiceImpl;
import com.hui.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "StudentChangeRoomExecuteServlet",urlPatterns = "/student/changeRoom/execute")
public class StudentChangeRoomExecuteServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String stuId = request.getParameter("stuId");
        String oldRoomName = request.getParameter("oldRoomName");
        String newRoomName = request.getParameter("newRoomName");

        IRoomService roomService=new RoomServiceImpl();
        RoomBean oldRoom = roomService.getRoomByRoomAddress(oldRoomName);
        RoomBean newRoom = roomService.getRoomByRoomAddress(newRoomName);

//        System.out.println(stuId+","+oldRoomName+","+newRoomName);

        IStudentService studentService=new StudentServiceImpl();
        studentService.changeStudentInRoom(Integer.parseInt(stuId),oldRoom.getRoomId(),newRoom.getRoomId());
        response.sendRedirect("/student/index");
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
